package com.example.touch.location;

import android.graphics.Point;

public class RoomLocation extends AbstractLocation
{
	// Presently, all rooms are defined as 2D bounding boxes.
	private Point lowerCorner;
	private Point upperCorner;
	
	public RoomLocation(Point lower, Point upper)
	{
		this.lowerCorner = lower;
		this.upperCorner = upper;
	}
	
	public RoomLocation(int lowerXPos, int upperXPos, int lowerYPos, int upperYPos)
	{
		this.lowerCorner = new Point(lowerXPos, lowerYPos);
		this.upperCorner = new Point(upperXPos, upperYPos);
	}
	
	public void setLowerCorner(Point lowerCorner)
	{
		this.lowerCorner = lowerCorner;
	}
	
	public void setUpperCorner(Point upperCorner)
	{
		this.upperCorner = upperCorner;
	}
	
	public Point getLowerCorner()
	{
		return lowerCorner;
	}
	
	public Point getUpperCorner()
	{
		return upperCorner;
	}
	
	@Override
	protected boolean handleIsWithin(Point currentPosition, int radius) 
	{
		int lowerX = Math.min(lowerCorner.x, upperCorner.x) - radius;
		int lowerY = Math.min(lowerCorner.y, upperCorner.y) - radius;
		int upperX = Math.max(lowerCorner.x, upperCorner.x) + radius;
		int upperY = Math.max(lowerCorner.y, upperCorner.y) + radius;
		
		return currentPosition.x >= lowerX && currentPosition.y >= lowerY
				&& currentPosition.x <= upperX && currentPosition.y <= upperY;
	}
}
